import request from '@/utils/request'

export interface DeviceUsageVO {
    usageId: number
    profileId: number
    serialNumber: string
    deviceName: string
    deviceModel: string
    category: string
    department: string
    lastStartTime: string | null
    usageDuration: number
    usageTimes: number
    todayUsageDuration: number
    createTime: string | null
    updateTime: string | null
    status: number
}

export interface PageResult<T> {
    records: T[]
    pages: number
    total: number
    size: number
    current: number
}

export const STATUS_MAP = {
    1: '运行中',
    2: '空闲',
    3: '故障待维修',
    4: '维修中',
    5: '已报废',
    6: '已注销',
    7: '维护中',
} as const

export type StatusType = keyof typeof STATUS_MAP  // '1' | '2' | ... 字符串字面量

export function getDeviceUsageList(
    page: number,
    size: number,
    deviceName?: string,
    deviceModel?: string,
    category?: string,
    department?: string,
    status?: number
) {
    return request.get<PageResult<DeviceUsageVO>>('/procedure/deviceUsages', {
        params: { page, size, deviceName, deviceModel, category, department, status }
    })
}


export function updateDeviceUsageStatus(id: number, status: number) {
    return request.put(`/procedure/deviceUsages/status/${id}`, null, {
        params: { status }
    })
}

// 获取运行中设备的今日使用时长（返回列表）
export async function getTodayUsageDuration(): Promise<{ data: { usageId: number, todayUsageDuration: number }[] }> {
    return await request.get('/procedure/deviceUsages/refresh')
}
